package project.active;

import model.pojo.Employee;
import project.dao.EmployeeDAO;
import project.dao.ProjectDAO;
import project.model.PrProject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import approve.action.R;

public class Laddmemmenu extends Activity {
	Bundle language;
	String lang="EN",database;
	PrProject pr =new PrProject();
	ProjectDAO prodao=new ProjectDAO();
	EmployeeDAO emdao=new EmployeeDAO();
	Employee emp=new Employee();
	//String[] idCheck=null;
	Button btGoProList;
	ListView lvmenu;
	TextView logout,username;
	L_list_subprolistmenu adsubprolist;
	String[] mnlst;
	
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	
	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.laddmemmenu);
		language = getIntent().getExtras().getBundle(getLang());
		
		btGoProList=(Button)findViewById(R.id.l_bt_MemmenugoProList);
		btGoProList.setText(language.getString("ac_SUProjectList"));
		lvmenu=(ListView)findViewById(R.id.lv_addmemmenu);
		
		Intent i=this.getIntent();
		pr=(PrProject)i.getSerializableExtra("project");		
		emp=(Employee)i.getSerializableExtra("em");
		
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));
		
		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		
		btGoProList.setOnClickListener(goprolist);
		mnlst=loadMemmenu();
		if(mnlst!=null){
			//lvmenu.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, loadMemmenu()));
			adsubprolist= new L_list_subprolistmenu(this, mnlst);
			lvmenu.setAdapter(adsubprolist);
		}
		
		lvmenu.setOnItemClickListener(goNext);
	}
	
	private OnItemClickListener goNext= new OnItemClickListener() {

		
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3) {
			// TODO Auto-generated method stub
			String item= arg0.getItemAtPosition(position).toString();
			if(item.equals(language.getString("add_coder"))){
				//showPopupCoder();
				Intent i= new Intent(Laddmemmenu.this,Laddcoder.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);
				i.putExtra("project", pr);
				//i.putExtra("lstcheck", idCheck);
				
				startActivity(i);
			}else if(item.equals(language.getString("add_tester")) ){
				//showPopupTester();
				Intent i= new Intent(Laddmemmenu.this,Laddtester.class);
				i.putExtras(getIntent().getExtras());
				i.putExtra("lang", getLang());
				i.putExtra("database", getDatabase());
				i.putExtra("em",emp);
				i.putExtra("project", pr);
				//i.putExtra("lstcheck", idCheck);
				
				startActivity(i);
			}
		}
	};
	
	public String[] loadMemmenu(){
		String[] menu = null;
    	menu= new String[2];
    	if(language.getString("add_coder").equals(null)==false){
    		menu[0]=language.getString("add_coder");
    	}else
    		menu[0]="";
    	
    	if(language.getString("add_tester").equals(null)==false){
    		menu[1]=language.getString("add_tester");
    	}else
    		menu[1]="";
    	return menu;
	}
	
	private OnClickListener goprolist = new OnClickListener() {
		
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i= new Intent(Laddmemmenu.this,Projectlist.class);
			i.putExtras(getIntent().getExtras());
			i.putExtra("lang", getLang());
			i.putExtra("database", getDatabase());
			i.putExtra("em",emp);
			
			startActivity(i);
		}
	};
	
//	public void showPopupCoder(){
//		AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
//		  helpBuilder.setTitle("Pop Up Coder");
//		  helpBuilder.setMessage("This is a Simple Pop Up");
//		  
//		  LayoutInflater inflater = getLayoutInflater();
//		  View checkboxLayout = inflater.inflate(R.layout.lpopupcoder, null);
//		  helpBuilder.setView(checkboxLayout);
//		  
//		  helpBuilder.setPositiveButton("Ok",
//		    new DialogInterface.OnClickListener() {
//
//		     public void onClick(DialogInterface dialog, int which) {
//		      // Do nothing but close the dialog
//		     }
//		    });
//
//		  // Remember, create doesn't show the dialog
//		  AlertDialog helpDialog = helpBuilder.create();
//		  helpDialog.show();
//	}
//	
//	public void showPopupTester(){
//		AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
//		  helpBuilder.setTitle("Pop Up tester");
//		  helpBuilder.setMessage("This is a Simple Pop Up");
//		  
//		  LayoutInflater inflater = getLayoutInflater();
//		  View checkboxLayout = inflater.inflate(R.layout.lpopupcoder, null);
//		  helpBuilder.setView(checkboxLayout);
//		  
//		  helpBuilder.setPositiveButton("Ok",
//		    new DialogInterface.OnClickListener() {
//
//		     public void onClick(DialogInterface dialog, int which) {
//		      // Do nothing but close the dialog
//		     }
//		    });
//
//		  // Remember, create doesn't show the dialog
//		  AlertDialog helpDialog = helpBuilder.create();
//		  helpDialog.show();
//	}
	
	private OnClickListener listenerLogout=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(Laddmemmenu.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};
}
